/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.inventory.impl;

import dao.inventory.HadiahDao;
import java.util.List;
import model.inventory.Hadiah;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.inventory.HadiahService;
import utility.StringUtils;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
@Service("hadiahService")
@Transactional(readOnly=true)
public class HadiahServiceImpl implements HadiahService{
    
    //avoid LazyInitializationException 
    String mainQuery = "from Hadiah hadiah left join fetch hadiah.mstUnit unit ";
    
    @Autowired private HadiahDao hadiahDao;

    @Transactional(readOnly=false)
    @Override
    public boolean save(Hadiah hadiah) {
        return hadiahDao.save(hadiah);
    }

    @Transactional(readOnly=false)
    @Override
    public boolean delete(Hadiah hadiah) {
        return hadiahDao.delete(hadiah);
    }

    @Override
    public Hadiah getHadiah(int id) {
        String query = mainQuery+" where hadiah.id = "+id;
        return hadiahDao.getByCustomQuery(query);
    }

    @Override
    public Hadiah getHadiah(String kode) {
        String query = mainQuery+" where hadiah.plu = "+StringUtils.fmtSQLString(kode);
        return hadiahDao.getByCustomQuery(query);
    }

    @Override
    public List<Hadiah> getHadiah() {
        return hadiahDao.getAll();
    }

    @Override
    public List<Hadiah> getHadiah(int start, int num) {
        return hadiahDao.getAll(start, num);
    }

    @Override
    public List<Hadiah> getHadiah(int start, int num, String params, String orderBy) {
        return hadiahDao.getAll(start, num, params, orderBy);
                
    }
    
}
